<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <button id="copyRoles">点击复制</button>
        <input id="clipBoard" />
        <div id="box"></div>
    </div>
    <script>
   var copyRoles =  document.getElementById('copyRoles');
   var clipBoard = document.getElementById('clipBoard');

   function cloneData(data){
        let input = document.createElement('input')
        input.id = 'orderId'
        input.value = data;
        input.readOnly = "readOnly"
        input.style.position="absolute";
        input.style.top = '-999px';
        input.style.opacity = '0';
        document.body.appendChild(input);
        input.select();
        if(document.execCommand('copy')) {
			document.execCommand('copy');
            document.getElementById('orderId').remove();
			console.log(`信息已复制成功`)
		} else {
			console.log('复制失败!')
		}
   }

   copyRoles.onclick=function(){
        console.log('22222')
        cloneData('22222222');
   }


    </script>
</body>
</html>